/**
 * @author Administrator
 * 多选择人员树
 */
var selectuserdutycheckwin,selectuserdutycheckididtager='',userdutychecksm, 
selectuserdutychecknametager='',selectuserdutychecknodetager = '',selectcheckuserdutysort='',selectcheckuserdutydutyname='',
checkuseridduty=new Ext.data.Store();
function initselectuserdutycheck(){
	/**
	 * 用户列表
	 */
		 Ext.BLANK_IMAGE_URL=Ext.get('basePath').getValue()+"ajaxFramework/ext-2.1/resources/images/default/s.gif";

	var userlisturl = Ext.get('basePath').getValue()+'tjsinfo/tjsoa/system/userByDutyName.do'
	selectcheckuserdutysort = new Ext.data.JsonStore({
		url:userlisturl,
		fields:['userId','uuid','userName']
	});
	userdutychecksm  = new Ext.grid.CheckboxSelectionModel({
		handleMouseDown:Ext.emptyFn
	});
	var cm = new Ext.grid.ColumnModel([
		userdutychecksm,
		{header: "用户名", width: 75, dataIndex: 'userName',menuDisabled : true},
		{header: "userId", width: 75, dataIndex: 'userId',menuDisabled : true,hidden:true},
		{header: "uuid", width: 75, dataIndex: 'uuid',menuDisabled : true,hidden:true}
	]);
	var grid = new Ext.grid.GridPanel({
		x:0,
	 	y:0,
		cm:cm,
		sm:userdutychecksm,
		anchor:'100% 100%',
		autoScroll: true,
		store:selectcheckuserdutysort,
		border: true,
	   	viewConfig:{
			forceFit:true	
		}
	});
	selectuserdutycheckwin = new Ext.Window({
		title:'人员选择',
		layout:'absolute',
		width:520,
		height:490,
		modal:true,
		closeAction:'hide',
		items:[grid],
		buttonAlign:'right',
		buttons:[{
			text:'保存',
			handler:function(){
				var userid="",username="",nodeid="";
				for(var i =0;i<userdutychecksm.getSelections().length;i++)
				{
					userid+=userdutychecksm.getSelections()[i].data.userId+",";
					username+=userdutychecksm.getSelections()[i].data.userName+",";
				}
				$('#'+selectuserdutycheckididtager).attr('value',userid);
				$('#'+selectuserdutychecknametager).attr('value',username);
				$('#'+selectuserdutychecknodetager).attr('value',nodeid);
				selectuserdutycheckwin.hide();
			}
		},{
			text:'取消',
			handler:function(){
				selectuserdutycheckwin.hide();		
			}
		}]
		
	})
}
/**
 * 打开人员的多选树
 * @param {} id
 * @param {} name
 */function selectuserdutycheckwinshow(id,name,nodeid,dutyname){
	selectuserdutycheckididtager = id;
	selectuserdutychecknametager = name;
	selectuserdutychecknodetager = nodeid;
	selectcheckuserdutydutyname  = dutyname;
	userdutychecksm,selectcheckuserdutysort.removeAll();
	var userid = $('#'+selectuserdutycheckididtager).attr('value');
	var username = $('#'+selectuserdutychecknametager).attr('value');
	var nodeid = $('#'+selectuserdutychecknodetager).attr('value');
	if(typeof(userid)   ==   'undefined')
	{
		checkuseridduty.removeAll();
	}
	else
	{
		
		checkuseridduty.removeAll();
		var useridarray = userid.split(",");
		var usernamearray = username.split(",");
		for(var i = 0;i<useridarray.length;i++)
		{
			checkuseridduty.addSorted(new Ext.data.Record({
				userId:useridarray[i],
				userName:usernamearray[i]
			}));
		}
	}
	selectcheckuserdutysort.load({
		params:{
			dutyname:selectcheckuserdutydutyname
		}
	})
	selectuserdutycheckwin.show();
}
